package com.laolang.gongda.bookshop.service.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.laolang.gongda.bookshop.domain.UserStatus;
import com.laolang.gongda.bookshop.service.UserStatusService;

@Transactional
@Service("userStatusService")
public class UserStatusServiceImpl implements UserStatusService {

	@PersistenceContext
	private EntityManager entityManager;

	@Override
	public void persist(UserStatus userStatus) {
		entityManager.persist(userStatus);

	}

	@Override
	public void remove(UserStatus userStatus) {
		entityManager.remove(entityManager.merge(userStatus));
	}

	@Override
	public void merge(UserStatus userStatus) {
		entityManager.merge(userStatus);
	}

	@Override
	public UserStatus find(Integer id) {
		return entityManager.find(UserStatus.class, id);
	}

	@Override
	public List<UserStatus> findUserStatusByStatusDesc(String statusDesc) {
		String hql = "SELECT o FROM UserStatus o WHERE o.statusDesc=:statusDesc";
		TypedQuery<UserStatus> query = entityManager.createQuery(hql, UserStatus.class);
		query.setParameter("statusDesc", statusDesc);
		return query.getResultList();
	}

}
